<template>
  <!-- 注册 -->
  <div class="signup">
    <div class="signup-header">
      <div class="signup-header-title">
        <HeaderLogo />
      </div>
      <div class="header-lang"></div>
    </div>
    <div class="signup-content">
      <div class="signup-content-left">
        <div class="signup-content-left-title">
          <p>{{ t('register.title') }}</p>
          <p>{{ t('register.desc') }}</p>
        </div>
        <div class="signup-content-left-svg">
          <SvgSignUp />
        </div>
      </div>
      <div class="signup-content-form">
        <el-form :model="ruleForm" :rules="rules" ref="formRef" size="large">
          <el-form-item label="" prop="username">
            <p class="signin-content-form-input-label">{{ t('register.username') }}</p>
            <el-input v-model="ruleForm.username" />
          </el-form-item>
          <el-form-item label="" prop="email">
            <p class="signin-content-form-input-label">{{ t('register.email') }}</p>
            <el-input v-model="ruleForm.email" />
          </el-form-item>
          <el-form-item label="" prop="password">
            <p class="signin-content-form-input-label">{{ t('register.password') }}</p>
            <el-input v-model="ruleForm.password" show-password />
          </el-form-item>
          <el-form-item label="" prop="confirmPassword">
            <p class="signin-content-form-input-label">{{ t('register.confirmPassword') }}</p>
            <el-input v-model="ruleForm.confirmPassword" show-password />
          </el-form-item>
          <el-form-item>
            <div class="signin-content-form-input-support">
              <el-checkbox v-model="ruleForm.termsOfService">
                {{ t('register.termsOfService') }}
              </el-checkbox>
              <p>
                <span>{{ t('register.alreadyHaveAccount') }}</span>
                <el-button type="primary" link @click="handleSignIn">{{
                  t('register.signInNow')
                }}</el-button>
              </p>
            </div>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="handleRegister" style="width: 100%">{{
              t('register.register')
            }}</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import HeaderLogo from '@/components/Header/HeaderLogo.vue';
import { useI18n } from 'vue-i18n';
import type { FormInstance } from 'element-plus';
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import SvgSignUp from '../svg/SvgSignUp.vue';
defineOptions({
  name: 'SignUp',
});
const { t } = useI18n();
const formRef = ref<FormInstance>();
const router = useRouter();
const ruleForm = ref({
  username: '', // 用户名
  password: '', // 密码
  confirmPassword: '', // 确认密码
  email: '', // 邮箱
  termsOfService: false, // 同意服务条款
});
const rules = ref({
  username: [{ required: true, message: t('register.usernameRequired'), trigger: 'blur' }],
  password: [{ required: true, message: t('register.passwordRequired'), trigger: 'blur' }],
  confirmPassword: [
    { required: true, message: t('register.confirmPasswordRequired'), trigger: 'blur' },
    {
      validator: (rule: any, value: any, callback: any) => {
        if (value !== ruleForm.value.password) {
          callback(new Error(t('register.confirmPasswordNotMatch')));
        }
      },
    },
  ],
  email: [{ required: true, message: t('register.emailRequired'), trigger: 'blur' }],
});
// 注册
const handleRegister = () => {
  formRef.value?.validate((valid) => {
    if (valid) {
      console.log('submit!');
    }
  });
};
// 登录
const handleSignIn = () => {
  router.push('/login');
};
</script>
<style lang="scss" scoped>
.signup {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background-color: rgba(106, 75, 255, 0.03);
  &:before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 200vh;
    height: 200vh;
    border-radius: 50%;
    background-color: #171725;
    transform: translate(50%, -25%);
    z-index: 1;
  }
  &-header {
    width: 100%;
    height: 108px;
    display: flex;
    align-items: center;
    padding: 0 32px;
    box-sizing: border-box;
  }
  &-content {
    width: 100%;
    height: calc(100% - 108px);
    display: flex;
    padding: 0 32px;
    box-sizing: border-box;
    align-items: center;
    justify-content: space-around;
    position: relative;
    z-index: 10;
    gap: 40px;
    &-left {
      width: 500px;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      align-items: center;
      &-title {
        display: flex;
        flex-direction: column;
        gap: 20px;
        p:first-child {
          font-size: 32px;
          font-weight: 600;
          letter-spacing: 4px;
        }
        p:last-child {
          font-size: 16px;
          font-weight: 400;
        }
      }
    }
    &-form {
      width: 484px;
      &-form {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
      }
    }
  }
}
</style>
